<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	//搜索
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['name']){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$total='';
	$list=pdo_getslice('jy_vote_kefus',$params,array($pindex,$psize),$total,$fields);
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'审核员列表'),
		),
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'paixu','title'=>'排序','type'=>'string'),
			array('name'=>'nickname','title'=>'审核员名称','type'=>'string'),
			array('name'=>'avatar','title'=>'审核员头像','type'=>'image'),
			array('name'=>'groupid','title'=>'审核员组','type'=>'radio','options'=>'groups'),
		)
		),
		'search_one'=>array('name'=>'name','add_op'=>'edit')
		
	);
	$return['groups']=pdo_getall('jy_vote_kfgroup',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_vote_kefus',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		$read=true;
	}else{
		$item=array();
		$read=false;
	}
	$return['groups']=pdo_getall('jy_vote_kfgroup',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'审核员详情',
		'edit_tab'=>true,
		'tabs'=>array(
			array('op'=>'list','title'=>'审核员列表'),
			array('op'=>'edit','title'=>'审核员详情'),
		),
		'edits'=>array(
			'0'=>array(
					'title'=>'基础设置',
					'list'=>array(
						array('type'=>'choose','title'=>'所属用户','name'=>'mid','op'=>'get_member','choose_title'=>'选择会员'),
						array('type'=>'string','title'=>'审核员名称','name'=>'nickname', 'help'=>'' ),
						array('type'=>'image','title'=>'审核员头像','name'=>'avatar', 'help'=>'' ),
						array('type'=>'select','title'=>'所属审核员组','name'=>'groupid','help'=>'','options'=>'groups'),
						array('type'=>'image','title'=>'审核员微信二维码','name'=>'kefuqr' , 'help'=>''),
						array('type'=>'switch','title'=>'是否开启','name'=>'isshow' , 'help'=>''),
						array('type'=>'string','title'=>'排序','name'=>'paixu' , 'help'=>''),
						)
			),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	if(!$post['groupid']){
		exi('请选择审核员组','error');
	}
	$data=array(
		'nickname'=>trim($post['nickname']),
		'name'=>trim($post['name']),
		'avatar'=>trim($post['avatar']),
		'groupid'=>intval($post['groupid']),
		'kefuqr'=>trim($post['kefuqr']),
		'paixu'=>intval($post['paixu']),
		'isshow'=>intval($post['isshow']),
		'mid'=>intval($post['mid']),
	);
	$id=intval($post['id']);
	if($id){
		pdo_update('jy_vote_kefus',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_vote_kefus',$data);
	}
	
	exi('保存成功！','','list');
}
if($_RQ['op']=='get_member'){
	//会员列表
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=$params=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$fields=array('username','nickname','mobile');
	if($_RQ['find']){
		$field=in_array($_RQ['field'],$fields)?$_RQ['field']:'nickname';
		$params[$field.' like']='%'.$_RQ['find'].'%';
		$return['params']['find']=$_RQ['find'];
		$return['params']['field']=$field;
	}
	$list=pdo_getslice('core_members',$params,array($pindex,$psize),$total,array('id','username','mobile','nickname','avatar'),'','id desc');
	if($list){
		foreach($list as &$item){
			$item['avatar'] = $item['avatar']?$item['avatar']:'../addons/jy_paimai/resource/images/userlogo.jpg';
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['htmls']=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'会员列表'),
		),
		'list'=>array('data'=>'list','del_one'=>false,'delall'=>false,'edit'=>false,'list'=>array(
		    array('name'=>'id','title'=>'会员id','type'=>'string'),
			array('name'=>'username','title'=>'会员账号','type'=>'string'),
			array('name'=>'mobile','title'=>'电话','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'id','title_field'=>'nickname','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'find','select_name'=>'field','select_title'=>'筛选','is_radio'=>true,'options'=>'fields'),
	);
	$return['fields']=array(
		'username'=>'会员账号',
		'nickname'=>'会员昵称',
		'mobile'=>'会员手机',
	);
	exi($return);
}

if($_RQ['op']=='del'){
	//删除小程序
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_vote_kefus',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_vote_kefus',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			}
		}
	}
	exi('删除成功！');
}
?>